using System;
using System.Collections.Generic;
using Rilisoft.MiniJson;
using UnityEngine;

public class ABTestingController : MonoBehaviour
{
	private const string ABTestingJSON_key = "ABTestingJSON";

	public static ABTestingController instance;

	public List<ABTestElement> abTestElementList;

	private void Awake()
	{
		instance = this;
		abTestElementList = new List<ABTestElement>();
		GetData();
	}

	private void GetData()
	{
		string aBTest = URLs.ABTest;
		ParsDataFromJson(JSONManager.Instance.GetJSON(aBTest));
	}

	private void ParsDataFromJson(string json)
	{
		if (string.IsNullOrEmpty(json))
		{
			return;
		}
		Dictionary<string, object> dictionary = Json.Deserialize(json) as Dictionary<string, object>;
		Dictionary<string, object> dictionary2 = (Dictionary<string, object>)dictionary["TestElements"];
		foreach (KeyValuePair<string, object> item2 in dictionary2)
		{
			Dictionary<string, object> dictionary3 = (Dictionary<string, object>)item2.Value;
			ABTestElement item = new ABTestElement(item2.Key, Convert.ToInt32(dictionary3["Percent"]), Convert.ToString(dictionary3["EnableForVersion"]));
			abTestElementList.Add(item);
			Debug.Log(item2.ToString());
		}
	}

	public ABTestElement GetABtestElement(string key)
	{
		foreach (ABTestElement abTestElement in abTestElementList)
		{
			if (abTestElement.key == key)
			{
				return abTestElement;
			}
		}
		return new ABTestElement(null, 0, string.Empty);
	}

	public void CreateJson()
	{
		Dictionary<string, object> obj = new Dictionary<string, object>();
		Dictionary<string, object> dictionary = new Dictionary<string, object>();
		Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
		dictionary2.Add("Percent", 200);
		dictionary2.Add("EnableForVersion", BuildNumberForInapps.BuildNumber);
		dictionary.Add("SkinExporterABTestPanel", dictionary2);
		string message = Json.Serialize(obj);
		Debug.Log(message);
	}
}
